/******************************************************************************
 * @Filename     : usci.h
 *
 * @Version      : V1.0
 * @Subversion   : $
 * @Last modified: 04/13/2020 16:01:41
 * @Modified by  : Mxy
 *
 * @Brief        : USCI driver header file
 *
 * Copyright (C) 2020 SKYRELAY Technology co.,Ltd All rights reserved.
 *****************************************************************************/
#ifndef __RC2412_USCI_H__
#define __RC2412_USCI_H__
//#include "udk.h"

#ifdef __cplusplus
extern "C"
{
#endif


#include "../../periph_def/rc2412_usci_def.h"


/** 
  * @brief  USCI-UART bps
  */
typedef enum
{
    UART_4800     = 4800,      /*!< Set baud rate to 4800 when UART clock is 32MHz */
    UART_9600     = 9600,      /*!< Set baud rate to 9600 when UART clock is 32MHz */
    UART_19200    = 19200,     /*!< Set baud rate to 19200 when UART clock is 32MHz */
    UART_38400    = 38400,     /*!< Set baud rate to 38400 when UART clock is 32MHz */
    UART_57600    = 57600,     /*!< Set baud rate to 57600 when UART clock is 32MHz */
    UART_76800    = 76800,     /*!< Set baud rate to 76800 when UART clock is 32MHz */
    UART_115200   = 115200,    /*!< Set baud rate to 115200 when UART clock is 32MHz */
    UART_153600   = 153600,    /*!< Set baud rate to 153600 when UART clock is 32MHz */
    UART_230400   = 230400,    /*!< Set baud rate to 230400 when UART clock is 32MHz */
    UART_256000   = 256000,    /*!< Set baud rate to 256000 when UART clock is 32MHz */
    UART_307200   = 307200,    /*!< Set baud rate to 307200 when UART clock is 32MHz */
    UART_460800   = 460800,    /*!< Set baud rate to 460800 when UART clock is 32MHz */
    UART_512000   = 512000,    /*!< Set baud rate to 512000 when UART clock is 32MHz */
    UART_921600   = 921600,    /*!< Set baud rate to 921600 when UART clock is 32MHz */
    UART_1382400  = 1382400,   /*!< Set baud rate to 1382400 when UART clock is 32MHz */
    UART_1843200  = 1843200,   /*!< Set baud rate to 1843200 when UART clock is 32MHz */
    UART_2000000  = 2000000,   /*!< Set baud rate to 2000000 when UART clock is 32MHz */
}uart_baudrate_t;	


/** 
  * @brief  USCI-UART Initial Structure definition
  */	
typedef struct
{
    uint32_t uart_baud_rate;         /*!< UART communication baud rate @ref uart_baud_rate */
    uint32_t uart_stop_bit ;                /*!< Specifies the number of stop bits transmitted. */
    uint32_t uart_parity_typ;               /*!< Specifies the parity mode. */
	  uint32_t uart_parity_en;                /*!< Parity enable. */
	  uint32_t uart_lsb;                      /*!< LSB & MSB. */
	  uint32_t uart_data_len;                 /*!< data lenth, 7,8,9 bit. */
} usci_uart_init_t;

/** 
  * @brief  USCI-SPI Initial structure definition  
  */
typedef struct
{
    uint32_t spi_mode;                /*!< Specifies the SPI mode (Master/Slave).*/
	  uint32_t spi_clkp;                
	  uint32_t spi_posedge;
	  uint32_t spi_msb;
	  uint32_t spi_data_len;
	  uint32_t spi_cs_level;
	  uint32_t spi_cs_gpio;
} usci_spi_init_t;

/** 
  * @brief  USCI-u7816 Initial structure definition  
  */
typedef struct
{
	  uint32_t u7816_speed;
    uint32_t u7816_stop_bit ;                  /*!< Specifies the number of stop bits transmitted. */
    uint32_t u7816_parity_typ;                 /*!< Specifies the parity mode. */
	  uint32_t u7816_parity_en;                  /*!< Parity enable. */
	  uint32_t u7816_lsb; 
	  uint32_t u7816_data_len; 
	  uint32_t u7816_invert;
} usci_u7816_init_t;

/** 
  * @brief USCI Transmit/Receive handler struct
  */
typedef struct
{ 
    USCI_T                     *instance;       /*!< USCI registers base address */
    union
    {
        usci_uart_init_t       u_init;          /*!< UART communication parameters */
        usci_spi_init_t        s_init;          /*!< SPI communication parameters */
			  usci_u7816_init_t      c_init;          /*!< 7816 communication parameters */
    };
		uint32_t                   usci_clock_div;  /*!< usci divide parameters */
} usci_handler_t;

//UART API function
uint8_t usci_Uart_Init(usci_handler_t *usci,uint8_t boot_pin);
uint8_t usci_Uart_Transmit(usci_handler_t *usci, uint8_t *tx_buf, int32_t size);
uint8_t usci_Uart_Receive(usci_handler_t *usci, uint8_t *rx_buf, int32_t size);


//SPI API function
uint8_t usci_Spi_Init(usci_handler_t *usci);
uint8_t usci_Spi_Transmit(usci_handler_t *usci, uint8_t *tx_buf, int32_t size);
uint8_t usci_Spi_Receive(usci_handler_t *usci, uint8_t *rx_buf, int32_t size);
uint8_t usci_Spi_TRx(usci_handler_t *usci, uint8_t *tx_buf, int32_t size, uint8_t *rx_buf);
uint8_t usci_Spi_Slave_Transmit(usci_handler_t *usci, uint8_t *tx_buf, int32_t size);
uint8_t usci_Spi_Slave_Receive(usci_handler_t *usci, uint8_t *rx_buf, int32_t size);


//U7816 API function
uint8_t usci_U7816_Init(usci_handler_t *usci);
uint8_t usci_U7816_Transmit(usci_handler_t *usci, uint8_t *tx_buf, int32_t size);
uint8_t usci_U7816_Receive(usci_handler_t *usci, uint8_t *rx_buf, int32_t size);
uint8_t usci_U7816_Cmd(usci_handler_t *usci, uint32_t cmd);


#ifdef __cplusplus
}
#endif
	
	
#endif

	
